﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// member 的摘要说明
/// </summary>
public class member
{
	public member()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}

    private static string GameConnStr =System.Configuration.ConfigurationSettings.AppSettings["gamestr"].ToString(); //ManagerConfiguration.GameDBConnectionString; //;

    private static string ConnStr = System.Configuration.ConfigurationSettings.AppSettings["gamestr"].ToString(); 

    #region 检验用户名

    /// <summary>
    /// 检查9158数据库是否存在(-1:系统错误 0:不存在 1;存在)
    /// </summary>
    /// <param name="uid"></param>
    /// <returns>-1:系统错误 0:不存在 1;存在</returns>
    public int IsExistMember(string uid)
    {
        int ret = -1;
        SqlParameter[] p ={
                SqlHelper.MakeInParam("@UserId",SqlDbType.VarChar,100,uid),
                SqlHelper.MakeOutParam("@Return",SqlDbType.Int,4,ret)};
        try
        {
            SqlHelper.ExecuteNonQuery(ConnStr, CommandType.StoredProcedure, "Register_CheckUserName", p);
            ret = Convert.ToInt32(p[1].Value);
        }
        catch (Exception ex)
        {
            ret = -1;
       //     ApplicationLog.WriteError(ApplicationLog.FormatException(ex, System.DateTime.Now.ToString()));
        }

        return ret;
    }


    /// <summary>
    /// 检查91555数据库是否存在(-1:系统错误 0:不存在 1;存在)
    /// </summary>
    /// <param name="uid"></param>
    /// <returns>-1:系统错误 0:不存在 1;存在</returns>
    public int IsExistMemberByGame(string uid)
    {
        int ret = -1;
        SqlParameter[] p ={
                SqlHelper.MakeInParam("@id",SqlDbType.VarChar,100,uid)};
        try
        {
            ret = (int)SqlHelper.ExecuteScalar(GameConnStr, CommandType.StoredProcedure, "GameWeb_Members_IsExist", p);
        }
        catch (Exception ex)
        {
            ret = -1;
       //     ApplicationLog.WriteError(ApplicationLog.FormatException(ex, System.DateTime.Now.ToString()));
        }
        return ret;
    }

    #endregion

    #region 用户登陆
    /// <summary>
    /// 获得91555数据库用户信息(登陆)(idx,id,coalesce(isVIP,0),fortune,userML)
    /// </summary>
    /// <param name="UserId"></param>
    /// <param name="Pwd_md5"></param>
    /// <returns></returns>
    public DataRow MemberGetInfoByLogin(string uid, string Pwd_md5)
    {
        //idx,id,coalesce(isVIP,0),fortune,userML

        DataTable dt = new DataTable();
        SqlParameter[] p =
			{
				SqlHelper.MakeInParam("@Id",SqlDbType.VarChar,20,uid),
				SqlHelper.MakeInParam("@Pwd",SqlDbType.VarChar,200,Pwd_md5)};
        try
        {
            dt = SqlHelper.ExecuteDataTable(GameConnStr, CommandType.StoredProcedure, "GameWeb_Members_Login", p);
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
            //ApplicationLog.WriteError(ApplicationLog.FormatException(ex, System.DateTime.Now.ToString()));
        }

        DataRow dr = null;
        if (dt != null && dt.Rows.Count != 0)
        {
            dr = dt.Rows[0];
        }
        else
            dr = null;

        return dr;
    }

    #endregion

    #region 用户信息
    /// <summary>
    /// 获得用户信息
    /// </summary>
    /// <param name="uid"></param>
    /// <returns></returns>
    public DataRow GetMemberInfo(string uid)
    {
        DataTable dt = new DataTable();
        SqlParameter[] p ={ SqlHelper.MakeInParam("@id", SqlDbType.VarChar, 20, uid) };
        try
        {
            dt = SqlHelper.ExecuteDataTable(GameConnStr, CommandType.StoredProcedure, "GameWeb_Members_GetMemberInfo", p);
        }
        catch (Exception ex)
        {
        //    ApplicationLog.WriteError(ApplicationLog.FormatException(ex, System.DateTime.Now.ToString()));
        }

        DataRow dr = null;
        if (dt != null && dt.Rows.Count != 0)
        {
            dr = dt.Rows[0];
        }

        return dr;
    }
    #endregion
}
